//
// Created on 2024/4/19.
//
// Node APIs are not fully supported. To solve the compilation error of the interface cannot be found,
// please include "napi/native_api.h".

#pragma once
#include "napi/native_api.h";
#include <thread>

#include <EGL/egl.h>
#include <EGL/eglext.h>
#include <EGL/eglplatform.h>
#include <GLES3/gl3.h>
#include <bits/alltypes.h>

//GFX 上下文，日后要改名
class glesmain {

public:
    void OnSurfaceCreateCB(void *component, void *window);//从Xcomponent 进入，做一些早期surface信息记录


public:
    uint64_t width;
    uint64_t height;
    EGLNativeWindowType m_egl_window;
    EGLDisplay m_eglDisplay= EGL_NO_DISPLAY;
    EGLConfig m_eglConfig = EGL_NO_CONFIG_KHR;
    EGLSurface m_eglSurface = EGL_NO_SURFACE;
    EGLContext m_eglContext_gfx = EGL_NO_CONTEXT;
    EGLContext m_eglContext_loader = EGL_NO_CONTEXT;
    sem_t sem_gfx_init;//gfx 初始化信号
    napi_ref ref_oninit = nullptr;
    napi_ref ref_onupdate = nullptr;
    napi_env cb_env = nullptr;

    char Reg_Input[64]; // 参数寄存器
    char Reg_Output[64];
    
    void GFX_Init();//创建GFX线程EGLContext;
    bool IsGFX_Init();
    void Dispatch_OnInit();//向ATKTS 发送oninit
    void StartVSyncThread(); //启动垂直同步线程，并在垂直同步时向ArkTs 发送onupdate

    void Cmd_Commit();
    void Cmd_Read();
};
